/**
 * Created by asus on 2017/10/9.
 */

public class ArrayStack<T> {
    private final int DEFAULT_CAPACITY = 10;
    private int count;
    private T[] stack;
    private T item;
    public T pop () {
        if (count==0){
            System.out.println("Wrong num");
        }
        else {
            item = stack[count-1];
            stack[count-1]=null;
        }
        return item;
    }
    public T peek(){
        if (count==0){
            System.out.println("Wrong num");
        }
        else {
            item = stack[count-1];
        }
        return item;
    }
    public boolean isEmpty(){
        if (count==0)
            return true;
        else
            return false;
    }
    public int size(){
        return count;
    }
    public ArrayStack(){
        count=0;
        stack =(T[])(new Object[DEFAULT_CAPACITY]);
    }
    public void push(T element){
        if (count==stack.length)
            expandCapacity();
        stack[count]=element;
        count++;
    }
    public String toString(){
        String result = "<top of stack>";
        for (int index=count-1;index>=0;index--)
            result += stack[index]+"\n";
        return result+"<bottom of stack>";
    }
    private void expandCapacity(){
        T[] larger = (T[])(new Object[stack.length*2]);
        for (int index=0;index<stack.length;index++){
            larger[index] = stack[index];

        }
        stack = larger;
    }
















}
